import cv2 as cv
import numpy as ny


def trackbar_callback(value):
    print('value = ', value)
    pass


def gauss_blur():
    win_name = 'dst name'
    t_name = 'kernel'
    src_img = cv.imread('..//lena.png')
    cv.imshow("source image", src_img)
    cv.namedWindow(win_name, cv.WINDOW_AUTOSIZE)
    cv.createTrackbar(t_name, win_name, 5, 50, trackbar_callback)
    while 1:
        val = cv.getTrackbarPos(t_name, win_name)
        # 内核的宽度和高度应为正数和奇数
        if val % 2:
            kernel = (val, val)
            print('kernel = ', kernel)
        dst_img = cv.GaussianBlur(src_img, kernel, 1)
        cv.imshow(win_name, dst_img)
        key = cv.waitKey(1)
        if key == 27:
            break


if __name__ == '__main__':
    gauss_blur()

